<template>
  <el-dialog
    width="70%"
    :title="!dataForm.id ? '商家收益' : '商家收益'"
    :close-on-click-modal="false"
    :modal="false"
    :visible.sync="visible">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList1()">
      <el-form-item>
        <el-input v-model="dataForm.keywords" placeholder="参数名" clearable></el-input>
      </el-form-item>
      <el-form-item label="用户类型">
		<el-select v-model="dataForm.userType" placeholder="用户类型">
          <el-option label="全部" value="" ></el-option>
			<el-option label="银行卡" value="0" ></el-option>
			<el-option label="微信" value="1" ></el-option>
			<el-option label="手动打款" value="2" ></el-option>
		  </el-select>
		</el-form-item>
      <el-form-item>
        <el-button @click="getDataList1()">查询</el-button>
        <el-tag>商家收益总额:{{moneyNum[0]}}</el-tag>
        <el-tag type="success">账户未提现余额:{{moneyNum[1]}}</el-tag>
        <el-tag type="info">推广可提现余额:{{moneyNum[2]}}</el-tag>
        <el-tag type="warning">账户已提现余额:{{moneyNum[3]}}</el-tag>
        <!-- <span style="font-size: 16px">商家收益总额:{{moneyNum[0]}}</span>&nbsp;&nbsp;
        <span style="font-size: 16px">账户未提现余额:{{moneyNum[1]}}</span>&nbsp;&nbsp;
        <span style="font-size: 16px">推广可提现余额:{{moneyNum[2]}}</span>&nbsp;&nbsp;
        <span style="font-size: 16px">账户已提现余额:{{moneyNum[3]}}</span> -->
        <!-- <el-button v-if="isAuth('generator:businesswithrecord:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button> -->
        <!-- <el-button v-if="isAuth('generator:businesswithrecord:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button> -->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <!-- <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column> -->
      <el-table-column
        prop="paUserName"
        header-align="center"
        align="center"
        label="支付账号">
      </el-table-column>
      <el-table-column
        prop="paUserTrueName"
        header-align="center"
        align="center"
        label="用户名称">
      </el-table-column>
      <el-table-column
        prop="paUserType"
        header-align="center"
        align="center"
        label="用户类型">
        <template slot-scope="scope">
          <p v-if="scope.row.paUserType == 1"> 区域运营商</p>
          <p v-else-if ="scope.row.paUserType == 2">普通联盟店</p>
          <p v-else-if ="scope.row.paUserType == 3">消费者</p>
          <p v-else-if ="scope.row.paUserType == 4">VIP会员</p>
          <p v-else-if ="scope.row.paUserType == 5">中级版联盟店</p>
          <p v-else-if ="scope.row.paUserType == 6">高级版联盟店</p>
          <p v-else-if ="scope.row.paUserType == 7">城市合伙人</p>
          <p v-else-if ="scope.row.userpaUserTypeType == 8">城市合伙人联盟店</p>
        </template>
      </el-table-column>
      <el-table-column
        prop="totalMoney"
        header-align="center"
        align="center"
        label="收益金额">
      </el-table-column>
      <el-table-column
        prop="storeTrueName"
        header-align="center"
        align="center"
        label="商家名称">
      </el-table-column>
      <el-table-column
        prop="storeUserName"
        header-align="center"
        align="center"
        label="商家手机号">
      </el-table-column>
      <el-table-column
        prop="storeUserType"
        header-align="center"
        align="center"
        label="商家类型">
        <template slot-scope="scope">
          <p v-if="scope.row.storeUserType == 1"> 区域运营商</p>
          <p v-else-if ="scope.row.storeUserType == 2">普通联盟店</p>
          <p v-else-if ="scope.row.storeUserType == 3">消费者</p>
          <p v-else-if ="scope.row.storeUserType == 4">VIP会员</p>
          <p v-else-if ="scope.row.storeUserType == 5">中级版联盟店</p>
          <p v-else-if ="scope.row.storeUserType == 6">高级版联盟店</p>
          <p v-else-if ="scope.row.storeUserType == 7">城市合伙人</p>
          <p v-else-if ="scope.row.storeUserType == 8">城市合伙人联盟店</p>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        label="订单创建时间"
        width="155px">
      </el-table-column>
      <el-table-column
        prop="orderType"
        header-align="center"
        align="center"
        label="订单类型">
        <template slot-scope="scope">
          <span v-if="scope.row.orderType == 1">线下订单</span>
          <span v-else-if="scope.row.orderType == 2">推广收益</span>
          <span v-else-if="scope.row.orderType == 3">线上订单</span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.orderId, scope.row.orderType)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <p><span><el-tag type="success" style="margin-left: 60%">支付金额:{{paymentAmount}}</el-tag></span><span style="margin-left: 50px"><el-tag type="info">支付消耗券:{{paymentVouchers}}</el-tag></span></p>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList1"></add-or-update>
  </el-dialog>
</template>

<script>
  import AddOrUpdate from './merchantIncome-add-or-update'
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          keywords: '',
          userType: '',
          id: 0
        },
        moneyNum: [],
        paymentAmount: 0,
        paymentVouchers: 0,
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList1()
    },
    methods: {
      init (id) {
        this.dataForm.id = id
        this.visible = true
        this.getDataList1()
      },
      // 获取数据列表
      getDataList1 () {
        this.visible = true
        this.dataListLoading1 = true
        this.$http({
          url: this.$http.adornUrl('/user/cashAudit/queryMerchantIncomeList'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'keywords': this.dataForm.keywords,
            'userType': this.dataForm.userType,
            'id': this.dataForm.id
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.moneyNum = []
            this.dataList = data.data.list[0].cashAuditListVO
            this.moneyNum.push(data.data.list[0].allMoney)
            this.moneyNum.push(data.data.list[0].notExtract)
            this.moneyNum.push(data.data.list[0].commissionMoney)
            this.moneyNum.push(data.data.list[0].yesExtract)
            this.totalPage = data.data.totalCount
            if (data.data.list[0].paymentAmount > 0) {
              this.paymentAmount = data.data.list[0].paymentAmount
            } else {
              this.paymentAmount = 0
            }
            if (data.data.list[0].paymentVouchers > 0) {
              this.paymentVouchers = data.data.list[0].paymentVouchers
            } else {
              this.paymentVouchers = 0
            }
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList1()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList1()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 详情
      addOrUpdateHandle (id, type) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id, type)
        })
      },
      // 商家收益
      addOrUpdateHandle1 (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 是否通过审核
      pass (id, type) {
        var combination
        combination = id + ',' + type
        this.$confirm(`确定进行操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/user/cashAudit/modifyCashAudit'),
            method: 'post',
            data: this.$http.adornData(combination, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList1()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.withrecordid
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/generator/businesswithrecord/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList1()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>
